import jwt
import datetime
from django.conf import settings


def create_token(payload, timeout=1):
    headers = {
        'typ': 'jwt',
        'alg': 'HS256'
    }

    payload['exp'] = datetime.datetime.utcnow() + datetime.timedelta(minutes=timeout)

    token = jwt.encode(
        payload=payload,
        key=settings.SECRET_KEY,
        algorithm='HS256',
        headers=headers
    )

    return token
